<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文件打包下载</title>
</head>
<body>
<button onclick="download()">点击下载</button>

<script>
    function download () {
        fetch('/download')
            .then(response => response.json())
            .then(({ path }) => {
                const name = path.split('/').pop()
                aLabelMockDownload(path, name)
            })
            .catch(console.error)
    }

    function aLabelMockDownload (path, name) {
        let a = document.createElement('a')
        a.href = location.protocol + '//' + location.host + '/' + path
        a.download = name
        a.click()
        a = null
    }
</script>
</body>
</html>
